package com.orchid.shop.common.exception;


import com.orchid.shop.model.vo.common.Result;
import com.orchid.shop.model.vo.common.ResultCodeEnum;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 统一异常类
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    //全局异常处理
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result error(Exception e){
        e.printStackTrace();
        return Result.build(null, ResultCodeEnum.SYSTEM_ERROR);
    }

    //自定义异常处理
    @ExceptionHandler(MyExceptionHandler.class)
    @ResponseBody
    public Result error(MyExceptionHandler e){
//        e.printStackTrace();
        return Result.build(null,e.getResultCodeEnum());
    }


}
